"""
读取完一边求和一边存 读取一次性求和存
1.先读取原本txt内容 read readline readlines
2.计算总分数
2.1分割split()
2.2求和 除了第一个数据以外的进行求和
2.3 拼接结果 姓名+总分数+换行\n
3.把列表的内容写进去
"""
# 第一种方式
# with open("初识NLTK.py.txt","r",encoding="utf-8") as f:
#     content = f.readlines()
# for i in content:
#     info = i.split()
#     sums = 0
#     for i in info[1:]:  # i是个字符串数据
#         sums+=int(i)
#     result = info[0]+"的总分数为："+str(sums)+"\n"  # 姓名+总分数
#     with open("result.txt","a",encoding="utf-8") as f:
#         f.write(result)
li = []
with open("初识NLTK.py.txt","r",encoding="utf-8") as f:
    content = f.readlines()
for i in content:
    info = i.split()
    sums = 0
    for i in info[1:]:  # i是个字符串数据
        sums+=int(i)
    result = info[0]+"的总分数为："+str(sums)+"\n"  # 姓名+总分数
    li.append(result)
with open("result.txt","w",encoding="utf-8") as f:
    f.writelines(li)